package com.thlws.redis.pubsub;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

/**
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisSub {


    public static void main(String[] args) throws Exception {

        try(Jedis jedis = new Jedis("localhost",6379);){

            //订阅后一直等待 新消息
            MySub sub = new MySub();
            jedis.subscribe(sub,"cctv");
        }
    }


    //消息处理
    static  class MySub extends JedisPubSub {
        @Override
        public void onMessage(String channel, String message) {

            System.out.println("channel = [" + channel + "], message = [" + message + "]");
        }
    }

}
